package edu.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;

import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.student.ejb.client.view.StudentServiceLocal;
import org.student.ejb.client.view.StudentServiceRemote;

public class StudentServlet extends HttpServlet {

	/**
	 * 
	 */

	private static final long serialVersionUID = -1411305864338647635L;
	@EJB
	private StudentServiceLocal studentServiceLocal;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html");
		processRequest(response);
	}

	private void processRequest(HttpServletResponse response) throws IOException {
		PrintWriter out = response.getWriter();
		Properties props = new Properties();
		InitialContext ctx = null;
		StudentServiceRemote studentServiceRemote = null;
		try {
			ctx = new InitialContext(props);
		} catch (NamingException e) {
			e.printStackTrace();
		}
		try {
			studentServiceRemote = (StudentServiceRemote) ctx
					.lookup("org.student.ejb.client.view.StudentServiceRemote");
		} catch (NamingException e) {
			e.printStackTrace();
		}
		if (studentServiceLocal != null)
			out.print("Hello World : " + studentServiceLocal + ":" + studentServiceRemote);

		out.flush();
		out.close();
	}
}
